#include "l_systems.h"


LSystem::LSystem()
{
	start="0";
}

LSystem::LSystem(std::string s, std::map<char,string> m)
{
	start=s;
	Rules=m;
}

void LSystem::SetStart(string s)
{
	start=s;
}

void LSystem::AddRule(char p, std::string s)
{
	Rules[p]=s;
}

void LSystem::RemoveRule(char p)
{
	map<char,string>::iterator it;

	it=Rules.find(p);

	if(it!=Rules.end())
		Rules.erase(it);

}

string LSystem::Expand(int level)
{
	string finalString=this->start;

	for(int i=0; i<level; i++)
	{
		string tmp=finalString;
		finalString.clear();

		for(int j=0; j<(int)tmp.length(); j++)
		{
			char c=tmp[j];

			if(Rules.find(c)!=Rules.end())
				finalString+=Rules[c];
			else
				finalString+=tmp[j];
		}

	}
	return finalString;
}